<?php 
include("header.inc");
// Requesting URL data
$progid = $_GET["progid"];
if(empty($progid) or !intval($progid)) { // If progid is not specified or contains wrong data
	header("Location: /"); // Redirecting to the main page
	exit;
}

// Connecting to database
if(!($link_id = mysql_connect($dbhost, $userid, $userpassword))) {
	die("<p><b>Error connecting to the database server:</b> " . mysql_error() . "</p>\n");
}
mysql_select_db($dbname);

// Receiving the required information from paddata
$result = mysql_query("SELECT * FROM paddata WHERE progid='$progid'", $link_id);
$query = mysql_fetch_array($result);
if(empty($query)) {
	header("HTTP/1.0 404 Not Found"); // Redirecting to the main page
	die("<p><b>No such entry in database!</b></p>\n");
}
$company      = htmlspecialchars($query["company"]);
$website      = htmlspecialchars($query["website"]);
$title        = htmlspecialchars($query["title"]);
$version      = $query["version"];
$cost         = sprintf("%01.2f",$query["cost"]);
$category     = $query["category"];
$ksize        = $query["ksize"];
$keywords     = str_replace(",",", ",htmlspecialchars($query["keywords"]));
$description  = htmlspecialchars($query["description"]);
$homepage     = $query["homepage"];
$download     = htmlspecialchars($query["download"],ENT_QUOTES);
$affiliate    = htmlspecialchars($query["affiliate"]);
$affiliateid  = $query["affiliateid"];
$dlcount      = $query["dlcount"];
$which_class  = $query["category"];

//Receiving custom URL from customurls if any
$result = mysql_query("SELECT customurl FROM customurls WHERE progid='$progid'", $link_id);
$query = mysql_fetch_array($result);
$customurl    =  htmlspecialchars($query["customurl"],ENT_QUOTES);
if(empty($customurl)) {
	$metadownload = $download;
}
else {
	$metadownload = $customurl;
}

// Establishing the displaying of software title with version
$fulltitle = $title . " " . $version;
?>
<meta http-equiv="Refresh" content="3; URL=<?php echo $metadownload; ?>">
<link rel="stylesheet" type="text/css" href="<?php echo $cssfile; ?>">
<table bgcolor="White" width="980" align="center">
<tr><td width="180" valign="top">
<table width=180 border=0 cellpadding=0 cellspacing=0 background="images/middle.gif">
          <tbody>
            <tr>
              <td height="2" class="table-top"></td>
            </tr>
            <tr>
              <td align=left valign=top class="left">
<?php

include_once('categories1.inc');
?>
</td>
            </tr>
            <tr>
              <td height="8" class="table-bottom"></td>
            </tr>
          </tbody>
        </table>
      <br>
        <table width=180 
            border=0 align="center" cellpadding=0 cellspacing=0 
            background="images/middle.gif">
          <tbody>
            <tr>
              <td width="8" height="2" class="table-top"></td>
              <td width="172" class="table-top"></td>
            </tr>
            <tr>
              <td align=left valign=center class="left-rss">:<br>
                  <br>
                  <p></p>
                <p></p></td>
              <td align=left valign=center class="left-rss"><span class="left-b"><img src="images/rss.gif" width="36" height="14">RSS Feeds</span><br>
                <img src="images/rss-1.gif" alt="new" width="14" height="14"><a href="rss.php">New Releases and Updates</a><br>
                  <img src="images/rss-1.gif" alt="new" width="14" height="14"><a href="rss.php?feed=popular">Most Popular Software</a><br>
                  <img src="images/rss-1.gif" alt="new" width="14" height="14"><a href="rss.php?feed=rating">Top Rated Software</a></td>
            </tr>
            <tr>
              <td height="8" colspan="2" class="table-bottom"></td>
            </tr>
          </tbody>
        </table>
&nbsp;</td>
<td valign="top">
<?php

// Establishing the displaying of category and subcategory links
$xcat  = rawurlencode($category);
$cdisp = explode("::", str_replace(" & "," &amp; ",$category));
$cmach = explode("%3A%3A", $xcat);
$cmach[0] = base64_encode($cmach[0]);
$xcat 	  = base64_encode($xcat);
$catlinks = "<b><a href=\"index02_w_" . $cmach[0] . ".html\">" . $cdisp[0] ."</a></b> \\ <b><a href=\"index02_w_" . $xcat . ".html\">" . $cdisp[1] ."</a></b> \\ <b><a href=\"index04_p_" . $progid . ".html\">" . $fulltitle ."</a></b> \\ <b>Download</b>";

//Establishing the displaying of order link
$buynowbtn = "";
if($affiliate && $affiliateid) {
	if($affiliate == "RegNow") {
		$affiliatelnk = "https://www.regnow.com/softsell/nph-softsell.cgi?affiliate=" . $regnowafl . "&item=" . $affiliateid;
	}
	if($affiliate == "Share-It") {
		$affiliatelnk = "https://secure.shareit.com/shareit/checkout.html?affiliateid=" . $shareitafl . "&productid=" . $affiliateid;
	}
	if($affiliate == "eSellerate") {
		$affiliatelnk = "http://store.esellerate.net/a.asp?c=0_" . $affiliateid . "_" . $esellerateafl;
	}
	if($affiliate == "Plimus") {
		$affiliatelnk = "https://www.plimus.com/jsp/buynow.jsp?contractId=" . $affiliateid . "&referrer=" . $plimusafl;
	}
	if($affiliatelnk) {
		$buynowbtn = "<a href=\"" . $affiliatelnk . "\"><img src=\"images/buy.gif\" border=\"0\" width=\"200\" height=\"25\" alt=\"Buy " . $fulltitle . "\"></a>";
	}
}

// Displaying code
echo "<table align=\"center\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\">\n";
echo "<tr>\n<td>\n";
echo "<p><b><a href=\"/\">C:</a></b> \\ " . $catlinks . "</p>\n";
echo "</td>\n</tr>\n</table><br>\n";
echo "<table class=\"tvisible\" align=\"center\" width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"4\">\n";
echo "<tr><td class=\"cat_0_expanded\"><p><b>Downloading " . $fulltitle . "</b> &nbsp; <span class=\"small\">by <a href=\"" . $website . "\" target=\"_blank\">" . $company . "</a></span></p>\n</td>\n</tr>\n";
echo "<tr>\n<td valign=\"top\"><br>\n";
echo "<p><b>" . $title . " description:</b> " . $description . ".. <br>[<a href=\"index04_p_" . $progid . ".html\">read more</a>]</p>\n";
echo "<h1>Connecting download server...</h1>\n";
echo "<p>If the download does not start automatically within 5 seconds, click the following link:</p>\n";
echo "<p><b><a href=\"" . $download . "\">Direct download link</a></b> (" . $ksize . " K).</p>\n";
echo "<p>Or refer to <a href=\"" . $homepage . "\">program home page</a>.</p>\n";
if($buynowbtn) {
	echo "<b><span class=\"red\">Note:</span></b> Software programs listed as <b>Shareware</b> and <b>Demo</b> are available for free downloads as Free-To-Try only. This means you can try the program and if you find ok for your needs buy it, otherwise stop using it.<br>To get the full version of <b>" . $fulltitle . "</b> you have to buy it for <b>\$" . $cost . "</b>.<br><br>\n" . $buynowbtn . "</p>\n";
}
echo "<br>\n</td>\n</tr>\n</table><br>\n";

// Increasing the downloads count
$dlcount += 1;
mysql_query("UPDATE paddata SET dlcount='$dlcount' WHERE progid='$progid'", $link_id);

// Displaying 10 most popular in related category
$numrows = 0;
$result = mysql_query("SELECT * FROM paddata WHERE category='$category' ORDER BY dlcount desc, pdate desc LIMIT 10", $link_id);
if($result) $numrows = mysql_num_rows($result);
echo "<table class=\"tvisible\" width=\"100%\" cellspacing=\"0\" cellpadding=\"4\">\n";
echo "<tr>\n<td class=\"cat_0_expanded\"><p><b>10 Most Popular in " . $cdisp[0] . " - " . $cdisp[1] . "</b></p></td>\n</tr>";

for ($i=0; $i<$numrows; $i++) {
	mysql_data_seek($result, $i);
	$query = mysql_fetch_array($result);
	
	$progid       = $query["progid"];
	$title        = htmlspecialchars($query["title"]);
	$version      = $query["version"];
	$description  = htmlspecialchars($query["description"]);
	$dlcount      = $query["dlcount"];
	$icon         = $query["icon"];
	
	// Establishing the displaying of program icon
	if($icon == "none") $iconimg = "img/noicon.gif";
	else $iconimg = $icon;
	
	// Displaying code
	echo "<tr>\n<td>\n";
	echo "<p><img src=\"" . $iconimg . "\" border=\"0\" width=\"32\" height=\"32\" align=\"left\"><b><a href=\"index04_p_" . $progid . ".html\">" . $title . " " . $version . "</a></b> &nbsp; <span class=\"small\">(Downloads: " . $dlcount . ")</span><br>\n" . $description . "</p>\n";
	echo "</td>\n</tr>\n";
}
echo "</table><br>\n";

// Disconnecting from database
mysql_close($link_id);
?>
<br>

</td><td class="tbody" width="182">

</td>
</tr>
</table>

</td></tr></table>
<?php
include_once('fooder.inc');
?>